#! python3
# updateProduce.py - Corrects costs in produce sales spreadsheet.

import os
import openpyxl

excelDir = os.path.join(os.getcwd(), 'materials', 'excel')

wb = openpyxl.load_workbook(os.path.join(excelDir, 'produceSales.xlsx'))
sheet = wb['Sheet']

# The produce types and their updated prices
PRICE_UPDATES = {'Garlic': 3.07,
                 'Celery': 1.19,
                 'Lemon': 1.27}

# Loop through the rows and update the prices.
for rowNum in range(2, sheet.max_row + 1): # skip the first row
    produceName = sheet.cell(row=rowNum, column=1).value
    if produceName in PRICE_UPDATES:
        sheet.cell(row=rowNum, column=2).value = PRICE_UPDATES[produceName]

resultFile = os.path.join('.temp', 'updatedProduceSales.xlsx')
wb.save(resultFile)